﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using YiSha.Util;
using YiSha.Util.Model;
using YiSha.Entity;
using YiSha.Model;
using YiSha.Admin.Web.Controllers;
using YiSha.Entity.QixingManage;
using YiSha.Business.QixingManage;
using YiSha.Model.Param.QixingManage;
using YiSha.Model.Result;
using YiSha.Web.Code;
using YiSha.Util.Extension;

namespace YiSha.Admin.Web.Areas.QixingManage.Controllers
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2023-03-19 19:39
    /// 描 述：商铺分类控制器类
    /// </summary>
    [Area("QixingManage")]
    public class GoodsCategoryController :  BaseController
    {
        private GoodsCategoryBLL goodsCategoryBLL = new GoodsCategoryBLL();

        #region 视图功能
        [AuthorizeFilter("qixing:goodscategory:view")]
        public ActionResult GoodsCategoryIndex()
        {
            return View();
        }

        public ActionResult GoodsCategoryForm()
        {
            return View();
        }
        #endregion

        #region 获取数据
        [HttpGet]
        [AuthorizeFilter("qixing:goodscategory:search")]
        public async Task<ActionResult> GetListJson(GoodsCategoryListParam param)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                //param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<GoodsCategoryEntity>> obj = await goodsCategoryBLL.GetList(param);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:goodscategory:search")]
        public async Task<ActionResult> GetPageListJson(GoodsCategoryListParam param, Pagination pagination)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                //param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<GoodsCategoryEntity>> obj = await goodsCategoryBLL.GetPageList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:goodscategory:search")]
        public async Task<IActionResult> GetCategoryTreeListJson(GoodsCategoryListParam param)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<ZtreeInfo>> obj = await goodsCategoryBLL.GetCategoryTreeListJson(param);
            return Json(obj);
        }

        [HttpGet]
        public async Task<ActionResult> GetFormJson(long id)
        {
            TData<GoodsCategoryEntity> obj = await goodsCategoryBLL.GetEntity(id);
            return Json(obj);
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("qixing:goodscategory:add,qixing:goodscategory:edit")]
        public async Task<ActionResult> SaveFormJson(GoodsCategoryEntity entity)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                entity.tenant_id = operatorInfo.tenant_id;
            }
            if (operatorInfo.IsSystem == 1 && !operatorInfo.tenant_id.IsNullOrZero())
            {
                entity.tenant_id = operatorInfo.tenant_id;
            }
            TData<string> obj = await goodsCategoryBLL.SaveForm(entity);
            return Json(obj);
        }

        [HttpPost]
        [AuthorizeFilter("qixing:goodscategory:delete")]
        public async Task<ActionResult> DeleteFormJson(string ids)
        {
            TData obj = await goodsCategoryBLL.DeleteForm(ids);
            return Json(obj);
        }
        #endregion
    }
}
